package se.karolinska.corticostriatal.ROI_plot;

import ij.gui.Roi;
import ij.plugin.frame.RoiManager;
import java.awt.Color;
import java.util.LinkedList;


/**
 *
 * @author Matthijs
 */
public class roiHandler {
    
    
    private static  RoiManager  manager;
    private static  Roi[]       ROIs;
    
    
    public roiHandler () {
        if (manager != null)
            manager.dispose();
        
        manager = ij.plugin.frame.RoiManager.getInstance();
        if (manager == null)
            manager = new ij.plugin.frame.RoiManager();
        manager.setVisible(true);
    }
    
    
    public static void showROIs (Color[] colors) {
        for (int i = 0; i < colors.length; i++) {
            ROIs[i].setStrokeColor(colors[i]);
            ROIs[i].setStrokeWidth(2);
        }
        manager.runCommand("Show All");
        manager.runCommand("Show Labels");
    }
    
    
    public static Roi getROI (int index) {
        return ROIs[index];
    }
    
    public static LinkedList<Roi> getROIs () {
        return new LinkedList<Roi>(manager.getROIs().values());
    }
    
    public static int getCount () {
        ROIs = manager.getRoisAsArray();
        return manager.getCount();
    }
    
    
    public static void hideManager () {
        if (manager != null)
            manager.close();
    }
}
